// map.js
import qqmap from '../../../utils/qqmap'
Page({
  data: {
    latitude: 28.194104,
    longitude: 113.013206,
    repairDetail:{},
    markerS:[
      {id:1,latitude:28.194104,longitude:113.013206,width:20,height:40},
      {id:2,latitude:27.875277,longitude:112.913237,width:20,height:40}]
  },
  onLoad({id}){
    this.getRepairDetail(id)
    qqmap.direction({
      mode:'driving',
      from:{
        latitude: 28.194104,
        longitude: 113.013206
      },
      to:{
        latitude: 27.875277,
        longitude: 112.913237
      },
      success:(res)=>{
           console.log(res);
        const coors = res.result.routes[0].polyline, pl = [];
        //坐标解压（返回的点串坐标，通过前向差分进行压缩）
        const kr = 1000000;
        for (var i = 2; i < coors.length; i++) {
          coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
        }
        //将解压后的坐标放入点串数组pl中
        for (let i = 0; i < coors.length; i += 2) {
          pl.push({ latitude: coors[i], longitude: coors[i + 1] })
        }
        // console.log(pl)
        this.setData({
          latitude:pl[0].latitude,
          longitude:pl[0].longitude,
          polyline: [{
            points: pl,
            color: '#000',
            width: 4
          }]
        })
      }
    })
  },
  //基础数据
  async getRepairDetail(id){
    if(!id) return wx.utils.toast('参数有误')
    const {code,data: repairDetail} = await wx.http.get('/repair/'+id)
    if(code!==10000) return wx.utils.toast()
    console.log(repairDetail);
    this.setData({
      repairDetail
    })
  },
  //点击取消业务
  async ontest(ev){
  console.log(ev.mark.id);
  const {code} =await wx.http.put('/cancel/repaire/'+ev.mark.id)
  if(code!==10000) return wx.utils.toast()
  wx.navigateTo({
    url: '/repair_pkg/pages/list/index',
  })
  }
 
  //repair_pkg/pages/list/index
  //长沙 28.194104 113.013206  // 27.875277 112.913237  湘潭
})
